package de.bht.fb6.cg1.exercise3.implement;
import de.bht.fb6.cg1.exercise3.Ring;

/**
 * Ring implementation of float
 */
public class FloatRing implements Ring<Float> {

	/**
	 * internal value
	 */
	protected Float number;

	/**
	 * create a new Ring to a value
	 * @param n value to set
	 */
	public FloatRing(final Float n) {
		set(n);
	}

	/**
	 * create a new Ring with 0 as initial value
	 */
	public FloatRing() {
		this(0f);
	}

	/**
	 * add another floatring
	 * @param value to add
	 * @return the result of calculation
	 */
	public Ring<Float> add(final Ring<Float> n) {
		return new FloatRing(number + n.get());
	}

	/**
	 * multiply the internal value n times
	 * @param n multiplier
	 * @return calculation result
	 */
	public Ring<Float> times(final Ring<Float> n) {
		return new FloatRing(number * n.get());
	}

	/**
	 * get the 1 element
	 * @return always 1f
	 */
	public Ring<Float> one() {
		return new FloatRing(1f);
	}

	/**
	 * subtract n from internal value
	 * @param n subtract value
	 * @return result of internal - n
	 */
	public Ring<Float> sub(final Ring<Float> n) {
		return new FloatRing(number - n.get());
	}

	/**
	 * get the zero element
	 * @return always 0f
	 */
	public Ring<Float> zero() {
		return new FloatRing(0f);
	}

	/**
	 * convert to string
	 * @return sting representation
	 */
	@Override
	public String toString() {
		return number.toString();
	}

	/**
	 * get the internal number
	 * @return internal value
	 */
	public Float get() {
		return number;
	}

	/**
	 * set the internal value
	 * @return internal value
	 */
	public void set(final Float n) {
		number = n;
	}

	/**
	 * creates a numeric hashcode
	 * @return numeric hashcode
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((number == null) ? 0 : number.hashCode());
		return result;
	}

	/**
	 * compares to obj
	 * @param obj the other object
	 * @return true if obj equals this
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FloatRing other = (FloatRing) obj;
		if (number == null) {
			if (other.number != null)
				return false;
		} else if (!number.equals(other.number))
			return false;
		return true;
	}
	
}
